package edu.chalmers.platypus.view.gui;

import java.awt.Cursor;
import java.awt.event.ActionEvent;

import javax.swing.JPanel;

import edu.chalmers.platypus.view.BatchThumbPanel;

/**
 * Clickable panel that adds images to batch
 */
public class AddImagePanel extends JPanel {

    /** Constructor */
    private AddImagePanel() {
	initComponents();
    }

    /** Constructor */
    public AddImagePanel(BatchThumbPanel listToAddTo) {
	this();
	this.listToAddTo = listToAddTo;
    }

    /**
     * Below: autogenerated NetBeans code
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed"
    // desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

	containerPanel = new javax.swing.JPanel();
	loadOverlayLabel = new javax.swing.JLabel();
	addButton = new javax.swing.JButton();

	org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application
		.getInstance().getContext().getResourceMap(AddImagePanel.class);
	setBackground(resourceMap.getColor("Form.background")); // NOI18N
	setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
	setName("Form"); // NOI18N
	setOpaque(false);

	containerPanel.setName("containerPanel"); // NOI18N
	containerPanel.setOpaque(false);
	containerPanel.setLayout(null);

	loadOverlayLabel
		.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
	loadOverlayLabel.setIcon(resourceMap.getIcon("loadOverlayLabel.icon")); // NOI18N
	loadOverlayLabel
		.setText(resourceMap.getString("loadOverlayLabel.text")); // NOI18N
	loadOverlayLabel.setName("loadOverlayLabel"); // NOI18N
	containerPanel.add(loadOverlayLabel);
	loadOverlayLabel.setBounds(0, 0, 120, 90);
	loadOverlayLabel.setVisible(false);

	addButton.setBackground(resourceMap.getColor("addButton.background")); // NOI18N
	addButton.setFont(resourceMap.getFont("addButton.font")); // NOI18N
	addButton.setIcon(resourceMap.getIcon("addButton.icon")); // NOI18N
	addButton.setText(resourceMap.getString("addButton.text")); // NOI18N
	addButton.setContentAreaFilled(false);
	addButton.setFocusable(false);
	addButton.setName("addButton"); // NOI18N
	addButton.addActionListener(new java.awt.event.ActionListener() {
	    public void actionPerformed(java.awt.event.ActionEvent evt) {
		addButtonActionPerformed(evt);
	    }
	});
	containerPanel.add(addButton);
	addButton.setBounds(0, 0, 120, 90);

	javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
	this.setLayout(layout);
	layout.setHorizontalGroup(layout.createParallelGroup(
		javax.swing.GroupLayout.Alignment.LEADING).addGroup(
		layout.createSequentialGroup()
			.addGap(0, 0, 0)
			.addComponent(containerPanel,
				javax.swing.GroupLayout.PREFERRED_SIZE, 120,
				javax.swing.GroupLayout.PREFERRED_SIZE)
			.addGap(0, 0, 0)));
	layout.setVerticalGroup(layout.createParallelGroup(
		javax.swing.GroupLayout.Alignment.LEADING).addGroup(
		javax.swing.GroupLayout.Alignment.TRAILING,
		layout.createSequentialGroup()
			.addGap(0, 0, 0)
			.addComponent(containerPanel,
				javax.swing.GroupLayout.PREFERRED_SIZE, 90,
				javax.swing.GroupLayout.PREFERRED_SIZE)
			.addGap(0, 0, 0)));
    }// </editor-fold>//GEN-END:initComponents

    /** Panel clicked, opens file chooser */
    private void addButtonActionPerformed(ActionEvent evt) {
	listToAddTo.openFileChooser();
    }

    /** Sets panel clickable and sets cursor to "hand" */
    public void setEnabled() {
	loadOverlayLabel.setVisible(false);
	addButton.setEnabled(true);
	this.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    }

    /**
     * Sets panel unclickable, shows loader animation and sets cursor to "wait"
     */
    public void setDisabled() {
	addButton.setEnabled(false);
	loadOverlayLabel.setVisible(true);
	this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addButton;
    private javax.swing.JPanel containerPanel;
    private javax.swing.JLabel loadOverlayLabel;
    // End of variables declaration//GEN-END:variables

    /** Reference to list that wants the images */
    private BatchThumbPanel listToAddTo;
}
